package website.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import website.advice.BaseResponse;
import website.domain.Comment;
import website.domain.Link;
import website.domain.Message;
import website.domain.ResModel;
import website.service.CommentService;
import website.service.LinkService;

import java.util.List;

@Api("评论控制类")
@BaseResponse
@RestController
@RequestMapping("/api/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("发布评论")
    @PostMapping(path = "",produces = "application/json")
    public ResModel issue(@RequestBody Comment comment){
        return commentService.issue(comment);
    }

    @ApiOperation("回复评论")
    @PostMapping(path = "/reply",produces = "application/json")
    public ResModel reply(@RequestBody Comment comment){
        return commentService.reply(comment);
    }

    @ApiOperation("查询评论")
    @GetMapping("/{current}/{size}/{rid}")
    public ResModel<IPage<Comment>> list(@PathVariable Integer current,@PathVariable Integer size,@PathVariable Integer rid){
        return commentService.getByPage(current,size,rid);
    }

    @ApiOperation("查询评论的回复")
    @GetMapping("/{rid}/{id}")
    public ResModel<List<Comment>> listReply(@PathVariable Integer rid,@PathVariable Integer id){
        return commentService.listReply(rid,id);
    }

    @ApiOperation("查询评论总数")
    @GetMapping("/{rid}")
    public ResModel count(@PathVariable Integer rid){
        return commentService.getCount(rid);
    }

    @ApiOperation("分页查询评论信息")
    @GetMapping("/list/{current}/{size}")
    public ResModel<IPage<Comment>> getByList(@PathVariable Integer current, @PathVariable Integer size){
        return commentService.getByList(current,size);
    }

    @ApiOperation("删除评论信息")
    @DeleteMapping("/{id}")
    public ResModel delComment(@PathVariable Integer id){
        return commentService.delComment(id);
    }
}
